using System;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class CityBuildingX2Button : MonoBehaviour
{
	public Image FillImage;

	public GameObject InactiveParent;

	public GameObject ActiveParent;

	public TextMeshProUGUI Timer;

	public TextMeshProUGUI MultiplierText;

	public CityBuildingElementData FirstBuildingData;

	private void Awake()
	{
		MultiplierText.text = "x" + 3;
		if (!FirstBuildingData.Unlocked)
		{
			base.gameObject.SetActive(value: false);
		}
	}

	public void OnClick()
	{
		if (!CityBuildingManager.Instance.IsX2Enable())
		{
			OnComplete(success: true);
		}
	}

	private void OnComplete(bool success)
	{
		if (success)
		{
			CityBuildingManager.Instance.OnX2GenerationClicked();
		}
	}

	private void Update()
	{
		TimeSpan timeSpan = CityBuildingManager.Instance.LastX2CollectPref.AddMinutes(5.0) - DateTime.Now;
		float num = (float)timeSpan.TotalMinutes / 5f;
		if (num <= 0f)
		{
			InactiveParent.SetActive(value: true);
			ActiveParent.SetActive(value: false);
			return;
		}
		InactiveParent.SetActive(value: false);
		ActiveParent.SetActive(value: true);
		FillImage.fillAmount = num;
		Timer.text = timeSpan.ToString("m\\:ss");
	}
}
